<template>
  <u-form-grid :data="formGrid" ref=""></u-form-grid>
</template>

<script>
  import values from '../../utils/values';
  import axios from 'axios';

  export default {
    name: 'OrderSendList',
    data () {
      return {
        formGrid: {
          exportParams: ["batchNo", "seqNo", "lastSendDmsTime"],
          options: {
            autoLoad: true,
            version: 'v2',
            url: {
              page: "orderIssue/page"
            }
          },
          toolbar: {
            create: {
              show: false
            },
            delete: {
              show: false
            },
            groups: {
              show: true,
              label: "数据导出",
              export: {
                url: "orderIssue/find",
                label: "导出全部",
                show: true,
                fileName: "下发经销商优惠券",
                columns: [
                  {title: '批次号', key: 'batchNo'},
                  {title: '订单编号', key: 'seqNo'},
                  {title: '总金额', key: 'amount'},
                  {title: '开始生效日期', key: 'validBeginDate'},
                  {title: '结束生效日期', key: 'validEndDate'},
                  {title: '发送DMS状态', key: 'sendDmsStatus'},
                  {title: '发送DMS时间', key: 'lastSendDmsTime'},
                  {title: '操作状态', key: 'cancel'},
                  {title: 'DMS反馈', key: 'dmsResult'},
                  {title: '发送历史', key: 'sendDmsHistory'},
                  {title: '推送消息', key: 'sendSmsStatus'}
                ]
              }
            },
            //关键字搜索框
            filter: {
              show: false,
              name: "keyWord",
              placeholder: "根据XXX搜索"
            },
            superFilter: {
              show: true,
              label: "高级搜索",
              width: 500,
              columns: [
                {type: "text", label: "批次号", name: "batchNo", icon: "plus", placeholder: "批次号"},
                {type: "text", label: "订单号", name: "seqNo", icon: "plus", placeholder: "订单号"},
                {type: "text", label: "活动名称", name: "name", icon: "plus", placeholder: "活动名称"},
                {type: "text", label: "活动代码", name: "campaignCode", icon: "plus", placeholder: "活动代码"},
                {type: "select", label: "发送DMS状态", name: "sendDmsStatus", items: [{"name": "待发送", "value": "待发送"}, {"name": "已发送", "value": "已发送"}], icon: "plus", placeholder: "请选择..."},
                {type: "select", label: "推送消息状态", name: "sendSmsStatus", items: [{"name": "待发送", "value": "待发送"}, {"name": "已发送", "value": "已发送"}], icon: "plus", placeholder: "请选择..."},
                {type: "date", label: "发送DMS时间开始", name: "lastSendDmsTimeStart"},
                {type: "date", label: "发送DMS时间结束", name: "lastSendDmsTimeEnd"}
              ],
              submit: {theme: "success", label: "查询", icon: "plus"}
            }
          },
          tips: {title: "订单下发", content: "根据条件：批次号，订单编号，发送时间查询等待下发的订单列表。还可以再操作订单，执行下发操作。"},
          form: {
            labelWidth: 120,
            modal: {
              title: "执行下发操作"
            },
            columns: [
              {label: "ID", type: "text", name: "id", required: false, readonly: true},
              {label: "批次号", type: "text", name: "seqNo", required: false, readonly: true},
              {label: "电子账户名称", type: "text", name: "name", required: false, readonly: true},
              {label: "VIN码", type: "text", name: "vin", required: false, readonly: true},
              {label: "活动编号", type: "text", name: "campaignCode", required: false, readonly: true},
              {label: "总金额", type: "text", name: "amount", required: false, readonly: true},
              {label: "已使用金额", type: "text", name: "useAmount", required: false, readonly: true},
              {label: "开始生效日期", type: "text", name: "validBeginDate", required: false, readonly: true},
              {label: "结束生效日期", type: "text", name: "validEndDate", required: false, readonly: true},
              {label: "目标经销商服务代码", type: "text", name: "targetDealer", required: false, readonly: true},
              {label: "使用经销商服务代码", type: "text", name: "useDealer", required: false, readonly: true},
              {label: "门槛金额", type: "text", name: "lowestAmount", required: false, readonly: true},
              {label: "抵扣限额", type: "text", name: "limitDeduct", required: false, readonly: true},
              {label: "发送DMS状态", type: "text", name: "sendDmsStatus", required: false, readonly: true},
              {label: "最近一次发送DMS时间", type: "text", name: "lastSendDmsTime", required: false, readonly: true},
              {label: "发送DMS的次数", type: "text", name: "sendDmsCount", required: false, readonly: true},
              {label: "认证车主手机号", type: "text", name: "customerMobile", required: false, readonly: true},
              {label: "发送操作状态", type: "text", name: "cancel", required: false, readonly: true},
              {label: "发送短信状态", type: "text", name: "sendSmsStatus", required: false, readonly: true},
              {label: "发送历史记录", type: "textarea", name: "sendDmsHistory", required: false, readonly: true},
              {label: "响应结果", type: "textarea", name: "dmsResult", required: false, readonly: true}
            ]
          },
          table: {
            showCheckbox: false,
            operation: {
              primaryKey: "id",
              buttons: [{
                key: "view", show: true, "label": "详情", "theme": "text", click: (row, index, _this) => {
                  _this.optViewClick(row, index);
                }
              }, {
                key: "edit", show: true, "label": "下发DMS", "theme": "primary", click: (row, index, _this) => {
                  //调用后端下发DMS接口
                  let req = {id: row.id};
                  axios.post("/orderIssue/savesenddown", req).then(response => {
                    let body = response.body;
                    console.info(body.code);
                    if (body.code === "200") {
                      this.$Message.success('下发DMS成功!');
                    }
                    else {
                      this.$Message.error({content: "下发DMS失败"});
                    }

                  }).catch(response => {
                    this.$Message.error({content: response});
                  })

                }
              }, {
                key: "delete", show: false, "label": "删除", "theme": "error", click: (row, index, _this) => {
                  _this.optDeleteClick(row, index);
                }
              }]
            },
            columns: [
              {title: '批次号', key: 'batchNo'},
              {title: '订单编号', key: 'seqNo'},
              {title: '总金额', key: 'amount'},
              {title: '开始生效日期', key: 'validBeginDate'},
              {title: '结束生效日期', key: 'validEndDate'},
              {title: '发送DMS状态', key: 'sendDmsStatus'},
              {title: '发送DMS时间', key: 'lastSendDmsTime'},
              {title: '操作状态', key: 'cancel'},
              {title: 'DMS反馈', key: 'dmsResult'},
              {title: '发送历史', key: 'sendDmsHistory', renderType: "tooltip"},
              {title: '推送消息', key: 'sendSmsStatus'}

            ]
          }
        }
      }
    },
    methods: {}
  }

</script>
